use actix_web::{HttpResponse, ResponseError};
use derive_more::{Display, From};

#[derive(Display, From, Debug)]
pub enum HandlerError {
    NotFound,
    Msg(String),
    SqlxError(sqlx::Error),
}

impl ResponseError for HandlerError {
    fn error_response(&self) -> HttpResponse {
        match *self {
            Self::NotFound => HttpResponse::NotFound().finish(),
            _ => HttpResponse::InternalServerError().body(format!("{:?}", self)),
        }
    }
}
